﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.Core;
using Castle.Core.Interceptor;
using Castle.DynamicProxy;
using AutofacContrib.DynamicProxy2;

namespace DemoAutofac.Models {
    public interface ILogger {
        void Write(string message);
    }

    public class Logger : ILogger {
        public void Write(string message) {
            Console.WriteLine(message);
        }
    }
    
    public class LogInterceptor : StandardInterceptor {
        private ILogger _logger;
        
        
        public LogInterceptor(ILogger logger) {
            _logger = logger;
        }


        protected override void PreProceed(IInvocation invocation) {
            _logger.Write(string.Format("Logger: Before Calling {0}",
                invocation.Method.Name));
        }

        protected override void PostProceed(IInvocation invocation) {
            _logger.Write("Logger: After Calling");
            base.PostProceed(invocation);
        }
    }
}
